/**
 * Created by hiibook on 2017/6/15.
 */
var wechatMsgConstruct = require('./wechatMsgConstruct'); //消息构建器
module.exports = function (req, res, next) {

    if (req.wechatMsg.MsgType == "event") {
        switch (true) {
            case /subscribe/.test(req.wechatMsg.Event):
                console.log('wechatSubscribe');
                subscribe(req, res, next);
                
                break;
            default:
                next();
                break;
        }
    } else {
        next()
    }

    function subscribe(req, res, next) {

        var chat = {
            Type: "text",
            Content: require('../config/config').subscription
        };
        // 最后一步需要信息,并关闭数据库连接
        req.mysqlConnection.end();
        res.send(wechatMsgConstruct(req.wechatMsg, chat));

    }

};